<?
layout("/inc/layout.html",{title:sysTitle}){
?>
<style>
	#tableactionTabContent .btn-default{
		margin-bottom: 15px;
	}
	#tableactionTabContent .btn-default.on{
		background: #086176;
    		color: #fff;
    		border-color: #064a59;
	}
	#tableactiondTab .btn-default.on{
		background: #086176;
    		color: #fff;
    		border-color: #064a59;
	}
	#tableactionTabContent{
		position: relative;
		/* height: 40px; */
		padding-top: 20px;
	}
	#tableactionTabContent .tab-pane{
		/* position: absolute; 
		left:52px;
		top:15px;
		float: right;
    	width: 94%;*/
    	width: 90%;
    	vertical-align: top;
	}
	#tableactionTabContent .tab-pane.fade{
		display:none;
	}
	#tableactionTabContent .tab-pane.fade.in{
		display:inline-block;
	}
</style>
<div id="page-wrapper">
      <!--BEGIN TITLE & BREADCRUMB PAGE-->
      <div id="title-breadcrumb-option-demo" class="page-title-breadcrumb">
          <div class="page-header pull-left">
              <div class="page-title">知识审核</div>
          </div>
          <ol class="breadcrumb page-breadcrumb pull-left">
              <li><i class="fa fa-home"></i>&nbsp;<a href="main.html">首页</a>&nbsp;&nbsp;<i class="fa fa-angle-right"></i>&nbsp;&nbsp;</li>
              <li>知识库管理&nbsp;&nbsp;<i class="fa fa-angle-right"></i>&nbsp;&nbsp;</li>
              <li class="active">知识审核</li>
          </ol>
           
          <div class="clearfix"></div>
      </div>
      <!--END TITLE & BREADCRUMB PAGE-->
      <!--BEGIN CONTENT-->
      <div class="page-content">
        <div class="row">
	        <div class="col-lg-4">
	            <div class="panel" style="height: 540px; overflow: auto;">
	                <div class="panel-heading">知识库</div>
	                <div class="panel-body" >
	                	<ul id="tree" class="ztree" style="width:270px"; overflow:auto;"></ul>
	                	<div id="dataNull" class="panel-body" style="height: 90px; line-height: 50px;" align="center"></div>
	                </div>
	            </div>
	        </div>
	        
	        <div class="col-lg-8">
	        	<div class="panel" style="height: 540px;overflow: auto;">
					<div class="input-group-sm mbs">
						<div class="col-lg-12">
						<div id="tableactiondTab" >
							
						</div>
                          <div id="tableactionTabContent">
                              
                          </div>
                      </div>
						<table style="width: 95%;">
							<tr height="50">
								<td align="right">标题：&nbsp;&nbsp;</td>
								<td>
									<input type="text" class="form-control" style="width: 100%;" id="text" name="text" />
								</td>
								<td align="right">
									<button class="btn btn-sm btn-success" style="margin-right: 10px;" onclick="demo(1)">搜索</button>
								</td>
								<td align="right">
									<button class="btn btn-sm btn-success" style="margin-right: 10px;" onclick="batchAuditYes()">批量通过</button>
								</td>
								<td align="right">
									<button class="btn btn-sm btn-red" style="margin-right: 10px;" onclick="batchAuditNo()">批量不通过</button>
								</td>
							</tr>
						</table>
						<div style="float: right;" id="dataCount"></div>
					</div>
	                <table class="table table-hover table-striped table-bordered table-advanced tablesorter mbn">
						<thead>
							<tr>
								<th ><input type="checkbox" class="checkall" name="onecheckall" /></th>
								<th >序号</th>
								<th >标题</th>
								<th >创建人 </th>
								<th >创建时间</th>
								<th >可操作</th>
							</tr>
						</thead>
						<tbody id="dataTbody">
							
						</tbody>
					</table>
					<div id="noData" style="display: none;text-align: center;">暂无数据...</div>
					<div id="page2" style="text-align: center; margin-top: 20px;"></div>
	            </div>
	        </div>
        </div>
        
      </div>
                     
    <!--END CONTENT-->
    </div>
<script src="static/layer-v2.0/layer/extend/layer.ext.js" type="text/javascript"></script>
<SCRIPT type="text/javascript" >
	var classid;
	var classname;
	var classnameEn;
	var curr;
	$(function() {
		initTree();
	});
	$(document).ready(function () { 
		$('#tableactiondTab').on('click','.btn-default',function(){
			var index=$(this).index();
			$(this).addClass('on').siblings().removeClass('on');
			$('#tableactionTabContent').find('.btn-default').removeClass('on');
			$('#tableactionTabContent .tab-pane').eq(index).find('.btn-default').eq(0).addClass('on');
			$('#tableactionTabContent .tab-pane').removeClass('in active');
			$('#tableactionTabContent .tab-pane').eq(index).addClass('in active');
			demo(1);
		});
		
		$('#tableactionTabContent').on('click','.btn-default',function(){
			$(this).addClass('on').siblings().removeClass('on');
			demo(1);
		});
		
	});
	function initTree() {
		$.ajax({
			type : "post",
			url : "./KnowledgeclassListall.do",
			dataType : "json",
			beforeSend : function(XMLHttpRequest) {
			},
			success : drawTree,
		});
	}

	function drawTree(data) {
		var setting = {
			view : {
				dblClickExpand : false,
			},
			data : {
				simpleData : {
					enable : true,
				}
			},
			check : {
				enable : false
			},
			callback : {
				onClick : onClick
			},
		};
		var zNodes = eval(data);
			if(data.length>0){
					$("#dataNull").hide();
				}else{
					$("#dataNull").html("<span class='subtitle' style=\"font-size: 15px;\">数据为空!</span>");
				}	
		$.fn.zTree.init($("#tree"), setting, zNodes).expandAll(true);
		zTree = $.fn.zTree.getZTreeObj("tree");
		zTree.expandNode(zTree.getNodes()[0], true);//指定某节点折叠
		var zTreeResult = zTree.getNodes();
		sum=zTreeResult.length;
	}
	function onClick(e, treeId, treeNode) {
		classid = treeNode.id;
		classname = treeNode.name;
		classnameEn = treeNode.nameEn;
		$('#tableactiondTab').html('');
		$('#tableactionTabContent').html('');
		demo(1);
	}
	function demo(curr) {
		var databaseId = $("#tableactiondTab input.on").attr("data-value");
		var chartName = $("#tableactionTabContent input.on").attr("data-value");
		$.getJSON("./getWorkflowExecute.do",
			{
				page : curr || 1,
				classnameEn : classnameEn,
				databaseId : databaseId,
				chartName : chartName,
        		text : $("#text").val(),
			},
			function(res) {
				//此处仅仅是为了演示变化的内容
				if(null != res[0].tableactiondTab && '' != res[0].tableactiondTab){
					$("#tableactiondTab").html("数据源："+res[0].tableactiondTab);
				}else{
					$("#tableactiondTab").html("");
				}
				if(null != res[0].tableactionTabContent && '' != res[0].tableactionTabContent){
					$("#tableactionTabContent").html("来源表："+res[0].tableactionTabContent);
				}else{
					$("#tableactionTabContent").html("");
				}
				var str='';
				for ( var i = 0; i <  res[0].data.length; i++) {
					str += "<tr><td><input type='checkbox' name='checkall' value='"+res[0].data[i].id+"'/></td><td>"
							+ (i + 1)
							+ "</td><td>"
							+ res[0].data[i].title
							+ "</td><td>"
							+ res[0].data[i].create_user_id
							+ "</td><td>"
							+ res[0].data[i].create_time
							+ "</td><td>"
							+ "<button type=\"button\" class=\"btn btn-default btn-xs\"onclick=\"queryDetails('"
							+ res[0].data[i].id
							+ "','"
							+ res[0].data[i].databaseId
							+ "','"
							+ res[0].data[i].chartName
							+ "')\">"
							+ "详情"
							+ "</button>&nbsp;"
							+ "<button type=\"button\" class=\"btn btn-default btn-xs\"onclick=\"yesPass('"
							+ res[0].data[i].id
							+ "')\">"
							+ "通过"
							+ "</button>&nbsp;"
							+ "<button type=\"button\" class=\"btn btn-default btn-xs\"  onclick=\"noPass('"
							+ res[0].data[i].id
							+ "')\">"
							+ "不通过"
							+ "</button>" + "</td></tr>";
				}
				$("#dataCount").html('当前数据量：'+res[0].pageCount);
				if('0' == res[0].pageCount){
					document.getElementById("noData").style.display="block";
				}else{
					document.getElementById("noData").style.display="none";
				}
				$("#dataTbody").html(str);
				laypage({
					cont : document.getElementById('page2'), //容器。值支持id名、原生dom对象，jquery对象,
					pages : res[0].page, //总页数
					skip : true, //是否开启跳页
					skin : 'molv', //加载内置皮肤，也可以直接赋值16进制颜色值，如:#c00
					curr: curr || 1,
					last: res[0].page,
					groups : 6,//连续显示分页数
					jump : function(obj, first) { //触发分页后的回调
						if (!first) { //点击跳页触发函数自身，并传递当前页：obj.curr
							demo(obj.curr);
			                 curr=obj.curr;
						}
					}
				});
			});
	};
	//审核不通过
	function noPass(id){
		var databaseId = $("#tableactiondTab input.on").attr("data-value");
		var chartName = $("#tableactionTabContent input.on").attr("data-value");
		layer.prompt({title: '输入不通过原因，并确认', formType: 2,  
		    yes : function(){  
		    	var pass =$(document.getElementsByClassName('layui-layer-input')[0]).val();  
		    	$.ajax({
					type : "post",
					data : {
						"id" : id,
						"classnameEn" : classnameEn,
						"pass" : pass,
						"databaseId" : databaseId,
						"chartName" : chartName,
					},
					url : "toAuditNoPass.do",
					dataType : "json",
					traditional : true,
					beforeSend : function(XMLHttpRequest) {},
					success : function(data){
						if(data=='yes'){
							layer.msg('审核成功！');
						}else{
							layer.msg('审核失败！');
						}
						demo(curr); 
						layer.close(1);  
					},
				});
		    }  
		});  
		
	}
	//审核通过
	function yesPass(id){
		var databaseId = $("#tableactiondTab input.on").attr("data-value");
		var chartName = $("#tableactionTabContent input.on").attr("data-value");
		if (confirm("是否确认通过！！")) {
		    	$.ajax({
					type : "post",
					data : {
						"id" : id,
						"classnameEn" : classnameEn,
						"databaseId" : databaseId,
						"chartName" : chartName,
					},
					url : "toAuditYesPass.do",
					dataType : "json",
					traditional : true,
					beforeSend : function(XMLHttpRequest) {},
					success : function(data){
						if(data=='yes'){
							layer.msg('审核成功！');
						}else{
							layer.msg('审核失败！');
						}
						demo(curr); 
					},
				});
		    }  
	}
	//批量审核通过
	function batchAuditYes(){
		var databaseId = $("#tableactiondTab input.on").attr("data-value");
		var chartName = $("#tableactionTabContent input.on").attr("data-value");
		var value=[];
		$("input[name='checkall']:checked").each(function(){
			value.push($(this).val());
		});
		if (confirm("是否确认通过！！")) {
		    	$.ajax({
					type : "post",
					data : {
						"value" : value,
						"classnameEn" : classnameEn,
						"databaseId" : databaseId,
						"chartName" : chartName,
					},
					url : "batchAuditYes.do",
					dataType : "json",
					traditional : true,
					beforeSend : function(XMLHttpRequest) {},
					success : function(data){
						if(data=='yes'){
							layer.msg('审核成功！');
						}else{
							layer.msg('审核失败！');
						}
						demo(curr); 
					},
				});
		    }  
	}
	//批量审核不通过
	function batchAuditNo(){
		var databaseId = $("#tableactiondTab input.on").attr("data-value");
		var chartName = $("#tableactionTabContent input.on").attr("data-value");
		var value=[];
		$("input[name='checkall']:checked").each(function(){
			value.push($(this).val());
		});
		layer.prompt({title: '输入不通过原因，并确认', formType: 2,  
		    yes : function(){  
		    	var pass =$(document.getElementsByClassName('layui-layer-input')[0]).val();  
		    	$.ajax({
					type : "post",
					data : {
						"value" : value,
						"classnameEn" : classnameEn,
						"pass" : pass,
						"databaseId" : databaseId,
						"chartName" : chartName,
					},
					url : "batchAuditNo.do",
					dataType : "json",
					traditional : true,
					beforeSend : function(XMLHttpRequest) {},
					success : function(data){
						if(data=='yes'){
							layer.msg('审核成功！');
						}else{
							layer.msg('审核失败！');
						}
						demo(curr); 
						layer.close(1);  
					},
				});
		    }  
		});  
		
	}
	//详情
	function queryDetails(detailsId,targetShardingDataSourceId,targetTableName){
		layer.open({
			type: 2,
			title: '详情',
			shadeClose: true,
			btn : [ '关闭' ],
			area: ['800px', '600px'],
			content: "querychoicerrelevance?classesId="+classid+"&id="+detailsId+"&dataSourceId="+targetShardingDataSourceId+"&targetTableName="+targetTableName,//iframe的url
			yes : function(index, layer) {
				var iframeWin = parent.window[layer.find('iframe')[0]['name']];
				iframeWin.save();
			},
			cancel : function(index) {
			}
		
			});
		}
</SCRIPT>    
    
  
<?} ?>
  
